<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <!--搜索-->
      <div class="panel-container">
        <SearchUiNew ref="SearchUiNew" :searchFormArr="searchFormArr" @searchParma="searchParma"></SearchUiNew>
      </div>
      <!--数据信息-->
      <div class="panel-container no-margin">
        <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="公司名称" prop="company_name" fixed="left" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="提交人" prop="sub_user_name" width="150"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="手机号" prop="sub_user_phone" width="150"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="标的物名称" prop="sub_goods_name" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="类型" prop="cate_type" width="100">
            <template slot-scope="scope">
              <!-- 1拍卖 2招标 -->
              <span v-if="scope.row.cate_type === 1">拍卖</span>
              <span v-if="scope.row.cate_type === 2">招标</span>
            </template>
          </af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="状态" prop="status">
            <template slot-scope="scope">
              <el-button type="text" @click="handleFeedBack(scope)">
                {{ scope.row.is_do === 1 ? '已处理' : '待处理' }}
              </el-button>
            </template>
          </af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="描述" prop="desc" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="备注" prop="remark" width="200"></af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="图片" prop="images" width="200">
            <template slot-scope="scope" v-if="showImages(scope.row.images).length > 0">
              <viewer :images="showImages(scope.row.images)" class="img-box" ref="viewer" :options="viewerOptions">
                <img v-for="item in showImages(scope.row.images)" :key="item" :src="item" class="img" />
              </viewer>
            </template>
          </af-table-column>
          <af-table-column align="center" header-align="center" show-overflow-tooltip label="信息提交时间" prop="created_time" width="150"></af-table-column>
        </el-table>
        <el-pagination
          small
          background
          :current-page="pageNumber"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pageTotal"
          @current-change="currentChangeHandle"
          @size-change="sizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
          style="margin-top: 20px; text-align: right"
        ></el-pagination>
      </div>
    </div>

    <!--  反馈 -->
    <el-dialog title="反馈" :visible.sync="showDialogFeedBack" :append-to-body="true">
      <DialogFeedBack v-if="showDialogFeedBack" @close="showDialogFeedBack = false" :id="currentId" :isDo="currentItem.is_do" :remark="currentItem.remark" @success="handleSuccess" />
    </el-dialog>
  </div>
</template>

<script>
import { apiNoticeFeedbackList } from '@/api/biddingNotice'
import DialogFeedBack from './DialogFeedBack.vue'

export default {
  name: 'DialogUserPublish',
  props: {
    time: Object,
  },
  components: { DialogFeedBack },
  data() {
    return {
      showDialogFeedBack: false,
      searchFormArr: [
        {
          fieldName: '处理状态',
          type: 'select',
          field: 'is_do',
          option: [
            { value: 1, label: '已处理' },
            { value: 2, label: '待处理' },
          ],
          placeholder: '请选择',
        },
        {
          fieldName: '信息提交时间:',
          type: 'timePicker',
          field: 'time',
          placeholder: '请选择信息提交时间',
          timeType: 'daterange',
          format: 'yyyy-MM-dd',
        },
      ],

      searchParams: {
        id_do: '',
        start_time: '',
        end_time: '',
      },
      dataList: [],
      pageNumber: 1,
      pageSize: 10,
      pageTotal: 0,
      dataListLoading: false,
      currentId: '',
      currentItem: {},
      viewerOptions: {
        button: true,
        navbar: false,
        title: true,
        toolbar: false,
        tooltip: false,
        movable: false,
        zoomable: true,
        rotatable: false,
        scalable: true,
        transition: false,
        fullscreen: false,
        keyboard: true,
        zIndex: 3000,
      },
    }
  },
  activated() {
    this.$refs.table.doLayout()
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      if (this.time) {
        const { start_time, end_time } = this.time
        this.searchParams.start_time = start_time
        this.searchParams.end_time = end_time
        this.$nextTick(() => {
          this.$refs.SearchUiNew.setItemValue([{ key: 'time', value: [start_time, end_time] }])
        })
      } else {
        this.getDataList()
      }
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      const info = Object.assign({ pageNumber: this.pageNumber, pageSize: this.pageSize }, this.searchParams)
      apiNoticeFeedbackList(info)
        .then((res) => {
          const { data, total } = res
          this.dataList = data
          this.pageTotal = total
          this.dataListLoading = false
          this.$refs.table.doLayout()
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 列表查询
    searchParma(e) {
      let list = ['time']
      this.searchFormArr.forEach((item) => {
        if (list.includes(item.field)) return
        if (e[item.field]) {
          this.searchParams[item.field] = e[item.field]
        } else {
          this.searchParams[item.field] = ''
        }
      })
      if (e.time) {
        this.searchParams.start_time = e.time[0]
        this.searchParams.end_time = e.time[1]
      } else {
        this.searchParams.start_time = this.searchParams.end_time = ''
      }
      this.pageNumber = 1
      this.getDataList()
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    handleFeedBack(scope) {
      this.currentId = scope.row.id
      this.currentItem = scope.row
      this.showDialogFeedBack = true
    },
    handleSuccess() {
      this.showDialogFeedBack = false
      this.getDataList()
    },
    showImages(images) {
      if (images) {
        return images.split('|')
      } else {
        return []
      }
    },
  },
}
</script>

<style scoped lang="scss">
.panel-line {
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.img {
  width: 30px;
  height: 30px;
  margin-right: 2px;
  cursor: pointer;
  &:last-child {
    margin-right: 0;
  }
}
</style>
